<template>
	<view class="app" :style="'background:'+bgdata.bg_color+';'+skin">
		<jnavbar :title="title" :bgdata="bgdata" :PageId="2"></jnavbar>
		<!-- <slist @onRefresh="onRefresh" class="page_container tab_page_container" ref="slist"> -->
		<block v-for="(item, i) in list" :key="i">
			<renovation :mydata="item.data"></renovation>
			<view v-if="is_merge && is_merge.length > 1 && item.name == 'member' && userInfo && !userInfo.is_success" @click="tomerge" class="merge_div">
				<view class="merge_left">
					<vimage class="image" imgtype="1" src="static/images/merge.png" mode=""></vimage>
					<view class="view">
						<text>账户合并</text>
						<text>快速合并多个账号，实现......</text>
					</view>
				</view>
				<view class="merge_btn">点我合并</view>
			</view>
			<renovation v-if="item.name == 'member' && userInfo && userInfo.is_write" :mydata="acceptdata"></renovation>
		</block>
		<renovation v-for="(item, index) in list1" :mydata="item.data" :key="item.name"></renovation>
		<guesslike ref="guesslike" page_id="4"></guesslike>
		<copyright></copyright>

		<!-- <u-gap height="60"></u-gap> -->
		<view class="version" @longpress="getversion"><text v-if="showversion">2.3.8</text></view>
		<tab-bar ref="tabbar" :PageId="2"></tab-bar>
		<floatmenu page_id="4"></floatmenu>
		<trolley></trolley>
		<nloading></nloading>
	</view>
</template>
<script>
import renovation from '@/components/renovation/index.vue';
import http from '@/common/http.js';
import {mapState, mapMutations} from 'vuex';
import copyright from '@/components/copyrights/index.vue';
export default {
	onShareAppMessage() {
		return this.wxShare();
	},
	data() {
		return {
			showversion: false,
			list: [],
			scrollTop: 0,
			title: '个人中心',
			acceptdata: {
				name: 'titleBar',
				content: {
					left: '核销入口',
					left_icon: 'el-sc-caidan1',
					right: '',
					right_icon: 'el-sc-gengduo'
				},
				titleBarType: 0,
				bar: {
					bg: '#fbda41',
					width: 5,
					height: 20
				},
				linkdata: {
					link: '../accept/index',
					name: '',
					id: '',
					type: '1',
					login_type: 2
				},
				color: {
					left: '#606266',
					left_icon: '#606266',
					right: '#909399',
					right_icon: '#909399',
					bg: '#FFFFFF'
				},
				posAlign: 'flex-start',
				radius: 20,
				margin: {
					top: 10,
					bottom: 10,
					lr: 10
				}
			},
			is_merge: [],
			bgdata: {},
			list1: []
		};
	},
	components: {
		renovation,
		copyright
	},
	computed: {
		...mapState({
			userInfo: state => state.userInfo,
			skin: state => state.skin
		})
	},
	async onLoad(e) {
		await this.$getWx;
		// #ifdef MP-WEIXIN
		wx.showShareMenu({
			withShareTicket: false,
			menus: ['shareAppMessage', 'shareTimeline']
		});
		// #endif
		this.getRenovation();
	},
	onShow() {
		var _this = this;

		this.judgeLogin(
			() => {},
			() => {
				_this.getjuris(['tradeSetting']).then(a => {
					// this.tradeSetting = a.tradeSetting;
				});
				_this.tokenToUserInfo();
			}
		);
	},
	onPullDownRefresh() {
		this.getRenovation();

		const _this = this;
		this.judgeLogin(
			() => {},
			() => {
				_this.tokenToUserInfo();
			}
		);
	},
	onReachBottom() {
		// console.log()
		this.$refs.guesslike.init();
	},
	methods: {
		getversion() {
			this.showversion = true;
			setTimeout(() => {
				this.showversion = false;
			}, 5000);
		},
		getMorePhone() {
			this.$http('/user/getMorePhone', {}, 'GET').then(res => {
				this.is_merge = res.data.msg;
			});
		},
		tomerge() {
			this.Jumpurl({
				link: '../mine/merge/merge',
				type: 1
			});
		},
		onRefresh() {
			this.getRenovation();
			const _this = this;
			this.judgeLogin(
				() => {},
				() => {
					_this.tokenToUserInfo();
				}
			);
		},
		toaccept() {
			this.Jumpurl({
				type: 1,
				link: '../accept/accept',
				login_type: 2
			});
		},
		userCenter(UserInfo) {
			let params = {};
			this.$http('/user/UserCenter', params, 'GET').then(res => {
				let centerinfo = res.data.msg;
				let myUserInfo = Object.assign({}, UserInfo, centerinfo);

				this.$store.commit('setUserInfo', myUserInfo);
				// this.getMorePhone();
			});
		},

		tokenToUserInfo() {
			let params = {};
			this.$http('/user/tokenToUserInfo', params, 'GET').then(res => {
				if (res.statusCode == 200) {
					let UserInfo = res.data.msg;
					this.userCenter(UserInfo);
					// this.$store.commit('setUserInfo', UserInfo);
				} else {
					this.$store.commit('setUserInfo', {});
					this.$store.commit('settoken', null);
				}
			});
		},
		getRenovation() {
			this.changeloading({loading: true});
			var data = {
				type: 3,
				merchant_id: 1
			};
			http('/Renovation/getRenovationInfo', data, 'GET').then(res => {
				// this.$refs.slist.afterload();
				uni.stopPullDownRefresh();
				this.changeloading({loading: false});
				this.$store.commit('setGid', this.$u.guid());
				if (res.statusCode == 200) {
					let data = res.data;
					let configure = JSON.parse(data.msg);
					this.bgdata = configure.page_config;
					uni.setNavigationBarTitle({
						title: configure.page_data.nav_name
					});
					this.title = configure.page_data.nav_name;
					this.list = configure.list;
					if (configure.list1) {
						this.list1 = configure.list1;
					}
				}
				this.$refs.guesslike.init();
			});
		}
	}
};
</script>

<style lang="scss">
.merge_div {
	display: flex;
	justify-content: space-between;
	width: 696rpx;
	height: 100rpx;
	background: linear-gradient(-90deg, #ffecd2, #fbeede);
	border-radius: 14rpx;
	align-items: center;
	margin: 20rpx 27rpx;
	padding: 23rpx;
	.merge_left {
		display: flex;
		align-items: center;
		.image {
			width: 37rpx;
			height: 37rpx;
		}
		.view {
			display: flex;
			flex-direction: column;
			margin-left: 22rpx;
			text:first-child {
				font-size: 30rpx;
				font-family: 59--Regular;
				font-weight: bold;
				color: #c79b57;
			}
			text:last-child {
				font-size: 18rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #dbb283;
			}
		}
	}
	.merge_btn {
		width: 138rpx;
		height: 44rpx;
		background: linear-gradient(-90deg, #f3c176, #f8debc);
		border-radius: 22rpx;
		text-align: center;
		line-height: 44rpx;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #7d5213;
		margin-right: 20rpx;
	}
}
.version {
	width: 100%;
	margin: 0 auto;
	height: 60rpx;
	text-align: center;
	line-height: 60rpx;
}
</style>
